TOP=$(shell pwd)

MIRACL_SRC_DIR=$(TOP)/miracl/src
SM2_SRC_DIR=$(TOP)/src/sm2
SM3_SRC_DIR=$(TOP)/src/sm3
SM4_SRC_DIR=$(TOP)/src/sm4

test_target=test_bin

# sm2,3,4
LIB_SRC = $(wildcard $(SM2_SRC_DIR)/*.c)
LIB_SRC += $(wildcard $(SM3_SRC_DIR)/*.c)
LIB_SRC += $(wildcard $(SM4_SRC_DIR)/*.c)
# miracl
LIB_SRC += $(wildcard $(MIRACL_SRC_DIR)/*.c)
# test
LIB_SRC += $(wildcard $(TOP)/test/*.c)

LIB_OBJ := $(patsubst %.c,%.o,$(LIB_SRC))

CC = gcc
CFLAGE = -Wall -g
INCLUDE_FLAGE = -I$(TOP)/inc/sm2/ -I$(TOP)/inc/sm3/ -I$(TOP)/inc/sm4/ -I$(TOP)/miracl/inc

all:$(test_target)

$(test_target): $(LIB_OBJ)
	$(CC) $(CFLAGE) $(INCLUDE_FLAGE) -o $@ $^

%.o : %.c
	$(CC) $(CFLAGE) $(INCLUDE_FLAGE) -c -fPIC $< -o $@

clean:
	rm $(LIB_OBJ) $(test_target)
